﻿package mortal.game.view.halidom.render
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import baseEngine.modifiers.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import extend.language.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import frEngine.primitives.object2d.*;
    import frEngine.render.layer.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.scene3D.model.pools.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.util.*;
    import mortal.mvc.core.*;

    public class HalidomRendererNew extends GSprite
    {
        private var _name:GBitmap;
        private var _lvBg:GBitmap;
        private var _txt:GTextFiled;
        private var _lv:BitmapNumberText;
        private var _data:THalidomSeriesConfig;
        private var _sHalidom:SHalidom;
        private var _nextLvInfo:THalidomConfig;
        private var _pos:Point;
        private var _isResCompl:Boolean;
        private var _itemBg:Img2D;
        private var _rect3d:Rect3DObject;
        private var _effectPlayer:EffectPlayer;

        public function HalidomRendererNew()
        {
            this.isHideDispose = true;
            return;
        }// end function

        public function set data(param1:THalidomSeriesConfig) : void
        {
            this._data = param1;
            var _loc_2:String = "";
            this._sHalidom = Cache.instance.halidom.getItemById(this._data.halidomId);
            if (this._sHalidom == null)
            {
                this._sHalidom = new SHalidom();
                this._sHalidom.halidomId = this._data.halidomId;
                this._sHalidom.level = 0;
                this._sHalidom.pieces = 0;
            }
            var _loc_3:* = HalidomConfig.instance.getItem(this._sHalidom.halidomId, this._sHalidom.level);
            this._nextLvInfo = HalidomConfig.instance.getItem(this._sHalidom.halidomId, (this._sHalidom.level + 1));
            if (_loc_3)
            {
                _loc_2 = _loc_2 + Language.getString(21510);
                _loc_2 = _loc_2 + AttributeUtil.setAttrByObj(_loc_3, 1);
                this._lv.text = _loc_3.level.toString();
            }
            else
            {
                this._lv.text = "0";
            }
            if (this._nextLvInfo)
            {
                _loc_2 = _loc_2 + Language.getString(21511);
                _loc_2 = _loc_2 + AttributeUtil.setAttrByObj(this._nextLvInfo);
            }
            this.add3DModel();
            return;
        }// end function

        public function get data() : THalidomSeriesConfig
        {
            return this._data;
        }// end function

        public function get sHalidom() : SHalidom
        {
            return this._sHalidom;
        }// end function

        public function set pos(param1:Point) : void
        {
            this._pos = param1;
            return;
        }// end function

        public function set rect3d(param1:Rect3DObject) : void
        {
            this._rect3d = param1;
            return;
        }// end function

        private function onSelect(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.HalidomSelectItem, (this._data.halidomId - 1)));
            return;
        }// end function

        private function updatePos() : void
        {
            this._txt.x = this._pos.x + 20;
            this._txt.y = this._pos.y + 59;
            this._name.x = this._pos.x + 30;
            this._name.y = this._pos.y + 135;
            this._lvBg.x = this._pos.x + 88;
            this._lvBg.y = this._pos.y + 135;
            this._lv.x = this._pos.x + 113;
            this._lv.y = this._pos.y + 135;
            return;
        }// end function

        private function add3DModel() : void
        {
            var _loc_1:BitmapData = null;
            if (this._isResCompl && this._data)
            {
                _loc_1 = GlobalClass.getBitmapData(ImagesConst.HalidomItemBg);
                if (this._rect3d && this._itemBg)
                {
                    this._rect3d.disposeObj3d(this._itemBg);
                    this._itemBg.dispose();
                    this._itemBg = null;
                }
                this._itemBg = new Img2D(null, _loc_1, new Rectangle(0, 0, _loc_1.width, _loc_1.height), true);
                this._itemBg.x = this._pos.x;
                this._itemBg.y = this._pos.y;
                if (this._effectPlayer)
                {
                    this._effectPlayer.dispose();
                }
                this._rect3d.disposeObj3d(this._effectPlayer);
                this._effectPlayer = EffectPlayerPool.instance.getEffectPlayer(this._data.effect, null, this._rect3d.renderList, false);
                this._effectPlayer.hangBoneName = BoneConst.MountHangModelBone;
                this._effectPlayer.play(PlayMode.ANIMATION_LOOP_MODE);
                this._rect3d.addObject3d(this._effectPlayer, this._pos.x + 58, this._pos.y + 55);
                this._rect3d.addImg(this._itemBg, Layer3DManager.BackGroudEffectLayer);
                this._name.bitmapData = GlobalClass.getBitmapData("HalidomName" + this._data.halidomId);
                this.updatePos();
            }
            return;
        }// end function

        private function onResCompl() : void
        {
            this._isResCompl = true;
            this.add3DModel();
            this._lvBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.HalidomLvTxt);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._name = UIFactory.gBitmap("", 0, 0, this);
            this._lvBg = UIFactory.gBitmap("", 0, 0, this);
            this._txt = UIFactory.gTextField("", 11, 184, 120, 90, this, GlobalStyle.textFormatChen.setSize(14).center());
            this._lv = UIFactory.bitmapNumberText(762, 436, "FightInfoNum.png", 12, 15, -1, this);
            configEventListener(MouseEvent.CLICK, this.onSelect);
            LoaderHelp.addResCallBack(ResFileConst.halidom, this.onResCompl);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            LoaderHelp.removeResEvent(ResFileConst.halidom, this.onResCompl);
            this._isResCompl = false;
            this._data = null;
            this._effectPlayer = null;
            this._txt.dispose(param1);
            this._name.dispose(param1);
            this._lvBg.dispose(param1);
            this._lv.dispose(param1);
            this._txt = null;
            this._name = null;
            this._lvBg = null;
            this._lv = null;
            this._itemBg = null;
            return;
        }// end function

    }
}
